package ${groupId}.${artifactIdProjectPackageName}.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;


public class DateUtils {

    public final static String yyyy_MM_dd = "yyyy-MM-dd";

    /**
     * 获取N分钟后的时间
     */
    public static Date getAfterMinute(Date date, int n) {
        Calendar instance = Calendar.getInstance();
        instance.setTime(date);
        instance.add(Calendar.MINUTE, n);
        return instance.getTime();
    }

    /**
     * 获取指定日期0时0分0秒的时间
     */
    public static Date get0h0m0s(Date date) {
        Calendar instance = Calendar.getInstance();
        instance.setTime(date);
        instance.set(Calendar.HOUR_OF_DAY, 0);
        instance.set(Calendar.MINUTE, 0);
        instance.set(Calendar.SECOND, 0);
        return instance.getTime();
    }

    /**
     * 获取指定日期23时59分59秒的时间
     */
    public static Date get23h59m59s(Date date) {
        Calendar instance = Calendar.getInstance();
        instance.setTime(date);
        instance.set(Calendar.HOUR_OF_DAY, 23);
        instance.set(Calendar.MINUTE, 59);
        instance.set(Calendar.SECOND, 59);
        return instance.getTime();
    }

    /**
     * 获取时间字符串
     * @param pattern
     * @param date
     * @return
     */
    public static String format(String pattern,Date date){
        SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);
        return dateFormat.format(date);
    }

}
